package mod.luckymod.effects;

import mod.luckymod.Luckymod;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.entity.LivingEntity;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class TetanusEffect extends MobEffect {
    public static final DeferredRegister<MobEffect> EFFECTS =
            DeferredRegister.create(ForgeRegistries.MOB_EFFECTS, Luckymod.MODID);

    public static final RegistryObject<MobEffect> TETANUS =
            EFFECTS.register("tetanus", TetanusEffect::new);
    public TetanusEffect() {
        super(MobEffectCategory.HARMFUL, 0x8B4513); // 有害效果，土褐色
    }

    @Override
    public void applyEffectTick(LivingEntity entity, int amplifier) {
        // 每等级增加1点伤害
        float damage = (amplifier + 1) * 1.0F;
        entity.hurt(entity.damageSources().magic(), damage);
    }
    @Override
    public boolean isDurationEffectTick(int duration, int amplifier) {
        // 等级越高，间隔越短，伤害频率越快
        // 例如：I级(0) 每40ticks(2秒)一次，II级(1) 每30ticks(1.5秒)一次，III级(2) 每20ticks(1秒)一次
        int baseInterval = 40;
        int interval = baseInterval - (amplifier * 10); // 根据等级调整间隔
        // 确保间隔不会小于一个最小值，例如10ticks（0.5秒）
        interval = Math.max(interval, 10);
        return duration % interval == 0;
    }
    public static void registerEffects(IEventBus bus) {
        EFFECTS.register(bus);
    }
}